const app = getApp()
Page({
  data: {
    icons: [],
    banner: [],
    stores:[],
    goodboxCurrent:1
  },
  //生命周期函数--监听页面加载
  onLoad: function (options){
    app.getParam(options);
    wx.setNavigationBarTitle({
      title: app.appname,
    })
    this.getApi();
  },
  //加载完成
  onReady: function () {
    setTimeout(()=>{
      this.setData({
        appConfig: app.globalData.appConfig
      })
    },1000)
  },
  //下拉刷新
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    setTimeout(()=>{
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    },1500);
    this.getApi();
  },
  //获取API
  getApi: function () {
    //广告
    app.api().Get('api/v4/allwin/adwords/index',{'ids':'icon/index'},(result) => {
      if (result.code == 200) {
        this.setData({
          icons:result.data.icon,
          banner:result.data.index,
        })
      }
    })
    //优选宝贝
    app.api().Get('api/v4/allwin/shop/index', {'signkey': app.util().getRandom(12)}, (result) => {
      if (result.code == 200) {
        this.setData({
          topshop: result.data,
        })
      }
    })
    //优选宝贝首页专题
    app.api().Get('api/v4/allwin/shop/indexSpecial', {'signkey': app.util().getRandom(12)},(result) => {
      if (result.code == 200) {
        this.setData({
          special: result.data,
        })
      }
    })
  },
  //分享按钮
  onShareAppMessage: function (res) {
    return {
      path: '/pages/index?ucode=' + app.globalData.loginuser.ucode
    }
  },
  //搜索
  onSearch: function (e) {
    wx.navigateTo({
      url: 'search?keyword='+e.detail,
    })
  },
  //产品切换到第几个了
  goodbox_swiper: function (event) {
    this.setData({
      goodboxCurrent: event.detail.current+1
    })
  },
})